package edu.cmu.javadb.plan;

import edu.cmu.javadb.plan.condition.Condition;
import edu.cmu.javadb.plan.visitor.Visitor;

public class Selection extends PlanNode {
	private PlanNode child;
	private Condition condition;
	
	public Selection() {
	}
	
	public Selection(PlanNode child, Condition condition) {
		setChild(child);
		this.condition = condition;
	}

	public Condition getCondition() {
		return condition;
	}

	public PlanNode getChild() {
		return child;
	}
	
	public void setChild(PlanNode child) {
		this.child = child;
		this.child.setFather(this);
	}
	
	@Override
	public String toString() {
		return "Selection" + "[" + getName() + "]: "  + (condition != null ? condition.toString() : "");
	}
	
	@Override
	public <T> T accept(Visitor<T> visitor) {
		return visitor.visitNode(this);
	}

	public void setCondition(Condition condition) {
		this.condition = condition;
	}



	@Override
	public <T> void visitChildren(Visitor<T> visitor) {
		child.accept(visitor);
	}
	
	@Override
	public boolean containsRelation(String name) {
		if (this.name.equals(name))
			return true;
		return child.containsRelation(name);
	}
}
